module.exports = function ($scope, $state, $resource, $modal) {

	$scope.maxSize = '5';			//最多显示多少个按钮
    $scope.currentPage = '1';		//当前页码
    $scope.itemsPerPage = '30'		//每页显示几条
	$scope.obj = {};
	$scope.status = {
		'list' : true,
		'flag' : false,
		'add' : false,
		'modify': false
	};

	$scope.logintype = [
		{'id': '0','name': '无需登录'},
		{'id': '1','name': '需要登录'},
	];

	//搜索
	$scope.search = function (pageNo){
		var para = {
            'pageNo': pageNo,
            'pageSize': $scope.itemsPerPage,
			'url': $scope.search.url,
			'searchType': $scope.search.searchType,
			'msg': $scope.search.msg
        };
		$resource('/api/ac/sc/systemFunction/getUserVisitList', {}, {}).save(para, function(res){
			if(res.errcode === 0){
				$scope.apiList = res.data.results;
				$scope.totalItems = res.data.totalRecord;
			}else{
				alert(res.errmsg);
			}
		});
	};

	$scope.search('1');

	//修改接口
	$scope.update = function (item){
		$scope.status = {
			'flag' : false,
			'modify': true
		};
		$scope.obj = item;
	}

	//添加接口
	$scope.add = function (){
		$scope.obj = {};
	}

	//保存
	$scope.save = function (){
		$scope.obj.state = $scope.obj.state == 0?'0':'1';
		$resource('/api/as/sc/uservisit/save', {}, {}).save($scope.obj, function(res){
			if(res.errcode === 0){
				$scope.cancel();
				$scope.search();
			}else{
				alert(res.errmsg);
			}
		});
	}

	//删除
	$scope.delete = function (index){
		if(confirm('确认要删除该用户吗？')==true){
			$resource('/api/as/sc/uservisit/delUserVisit', {}, {}).save($scope.apiList[index], function(res){
				if(res.errcode === 0){
					$scope.apiList.splice(index, 1);
				}else{
					alert(res.errmsg);
				}
			});
		}
	}

	//启用
	$scope.open = function (item){
		$scope.status.flag = true;
		$scope.status.add = true;
		$scope.obj = angular.copy(item);
		$scope.obj.state = 0;
		$scope.obj.type = '1';
	}

	//取消
	$scope.cancel = function (){
		$scope.status = {
			'list' : true,
			'flag' : false,
			'add' : false,
			'modify': false
		};
	}


};